/*
 * @Author: chentao 
 * @Date: 2022-08-29 10:17:49 
 * @Last Modified by: chentao
 * @Last Modified time: 2023-12-10 19:02:09
 */
import actionTypes from '../types'
import type { INavBarState, IHttpResponse } from '@/interface'


const navBarResetState: INavBarState = {
  bindLoading: false,
  aitdMintCount: 1,
  usdtMintCount: 1,
  inviteLink: '',
  minTotalNum: 0,
  currentUserMintNum: 0,
  singleAitdPrice: 0,
  singleUsdtPrice: 0,
  usdtTotalMoney: 0, //usdt总额度
  tokenBalanceNum: 0 //授权额度  

}

interface IState {
  navBarState: INavBarState
  response: IHttpResponse<String>
}
const initState = JSON.parse(JSON.stringify(navBarResetState))
interface IAction<T> {
  type: string
  payload: T
}
function reducer(state: IState, action: IAction<INavBarState>) {
  //state是一个immutable的，也就是不变的
  let newNavBarState: INavBarState
  switch (action.type) {
    case actionTypes.navBarActionType.AITD_ADD:
      newNavBarState = JSON.parse(JSON.stringify(state.navBarState))
      newNavBarState.aitdMintCount++
      const newState = { ...state, navBarState: newNavBarState }
      return newState
    case actionTypes.navBarActionType.AITD_DECREMENT:
      newNavBarState = JSON.parse(JSON.stringify(state.navBarState))
      newNavBarState.aitdMintCount--
      return { ...state, navBarState: newNavBarState };
    case actionTypes.navBarActionType.STATION_LIST:
      const payload = action.payload
      return {
        ...state,
        ...payload
      }
    default:
      return { ...state }
  }
}
export default {
  initState,
  reducer,
};
